package com.wsm.common.business.impl;

import com.wsm.common.business.BlackipBusiness;
import com.wsm.common.domain.BlackipDO;
import com.wsm.common.service.BlackipService;
import com.wsm.common.utils.PageUtils;
import com.wsm.common.utils.Query;
import com.wsm.common.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 访问黑名单
 *
 * @author wangshimin
 * @email wangshiminhome@foxmail.com
 * @date 2020-02-17 17:03:32
 * @description : 访问黑名单
 */
@Service
public class BlackipBusinessImpl implements BlackipBusiness {
	@Autowired
	private BlackipService blackipService;

	@Override
	public BlackipDO get(Long id) {
		return blackipService.getById(id);
	}

	@Override
	public Result<PageUtils> list(Map<String, Object> params) {
		//查询列表数据
		Query query = new Query(params);
		List<BlackipDO> blackipList = blackipService.list(query);
		int total = blackipService.count(query);
		PageUtils pageUtils = new PageUtils(blackipList, total);
		return Result.success(pageUtils);
	}

	@Override
	public Result save(BlackipDO blackip) {
		if (blackipService.orSave(blackip) > 0) {
			return Result.success();
		}
		return Result.error();
	}

	@Override
	public Result update(BlackipDO blackip) {
		blackipService.update(blackip);
		return Result.success();
	}

	@Override
	public Result remove(Long id) {
		if (blackipService.remove(id) > 0) {
			return Result.success();
		}
		return Result.error();
	}

	@Override
	public Result batchRemove(Long[] ids) {
		blackipService.batchRemove(ids);
		return Result.success();
	}

	public Result removeOrDel(Long id) {
		if (blackipService.removeOrDel(id) > 0) {
			return Result.success();
		}
		return Result.error();
	}

	public Result batchRemoveOrDel(Long[] ids) {
		blackipService.batchRemoveOrDel(ids);
		return Result.success();
	}

	public Result updateUseFlag(Long id, Integer useFlag) {
		if (blackipService.updateUseFlag(id, useFlag) > 0) {
			return Result.success();
		}
		return Result.error();
	}

}
